<?php
declare(strict_types=1);
/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://gitee.com/xmo/MineAdmin
 */

namespace App\Record\Mapper;

use App\Record\Model\RecordPaymentSuccess;
use Hyperf\Database\Model\Builder;
use Mine\Abstracts\AbstractMapper;

/**
 * 成功订单记录Mapper类
 */
class RecordPaymentSuccessMapper extends AbstractMapper
{
    /**
     * @var RecordPaymentSuccess
     */
    public $model;

    public function assignModel()
    {
        $this->model = RecordPaymentSuccess::class;
    }

    /**
     * 搜索处理器
     * @param Builder $query
     * @param array $params
     * @return Builder
     */
    public function handleSearch(Builder $query, array $params): Builder
    {
        
        // Id
        if (isset($params['id']) && filled($params['id'])) {
            $query->where('id', '=', $params['id']);
        }

        // 用户id
        if (isset($params['user_id']) && filled($params['user_id'])) {
            $query->where('user_id', '=', $params['user_id']);
        }

        // 上级ID
        if (isset($params['parent_id']) && filled($params['parent_id'])) {
            $query->where('parent_id', '=', $params['parent_id']);
        }

        // 用实际到账
        if (isset($params['fact_money']) && filled($params['fact_money'])) {
            $query->where('fact_money', '=', $params['fact_money']);
        }

        // 到账金额
        if (isset($params['received_amount']) && filled($params['received_amount'])) {
            $query->where('received_amount', '=', $params['received_amount']);
        }

        // 内部订单号
        if (isset($params['order_sn']) && filled($params['order_sn'])) {
            $query->where('order_sn', 'like', '%'.$params['order_sn'].'%');
        }

        // 外部订单号
        if (isset($params['transaction_id']) && filled($params['transaction_id'])) {
            $query->where('transaction_id', 'like', '%'.$params['transaction_id'].'%');
        }

        // 支付方式
        if (isset($params['method_id']) && filled($params['method_id'])) {
            $query->where('method_id', '=', $params['method_id']);
        }

        // 支付名称
        if (isset($params['method_name']) && filled($params['method_name'])) {
            $query->where('method_name', 'like', '%'.$params['method_name'].'%');
        }

        // 创建人
        if (isset($params['created_by']) && filled($params['created_by'])) {
            $query->where('created_by', '=', $params['created_by']);
        }

        // 创建时间
        if (isset($params['create_time']) && filled($params['create_time'])) {
            $query->where('create_time', '=', $params['create_time']);
        }

        // 修改时间
        if (isset($params['update_time']) && filled($params['update_time'])) {
            $query->where('update_time', '=', $params['update_time']);
        }

        return $query;
    }
}